package com.ruoyi.develop.goodsSaledoGongxu.service.impl;

import java.util.List;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.DateUtils;
        import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.ruoyi.develop.goodsSaledoGongxu.mapper.GoodsSaledoGongxuMapper;
import com.ruoyi.develop.goodsSaledoGongxu.domain.GoodsSaledoGongxu;
import com.ruoyi.develop.goodsSaledoGongxu.service.IGoodsSaledoGongxuService;

/**
 * 订单产品工艺工序关联Service业务层处理
 * @author qh
 * @date 2024-11-03
 */
@Service
public class GoodsSaledoGongxuServiceImpl implements IGoodsSaledoGongxuService {
    @Resource
    private GoodsSaledoGongxuMapper goodsSaledoGongxuMapper;

    /**
     * 查询订单产品工艺工序关联
     * @param id 订单产品工艺工序关联主键
     * @return 订单产品工艺工序关联
     */
    @Override
    public GoodsSaledoGongxu selectById(String id) {
        return goodsSaledoGongxuMapper.selectById(id);
    }

    /**
     * 查询订单产品工艺工序关联列表
     * @param entity 订单产品工艺工序关联
     * @return 订单产品工艺工序关联
     */
    @Override
    public List<GoodsSaledoGongxu> selectList(GoodsSaledoGongxu entity) {
        return goodsSaledoGongxuMapper.selectList(entity);
    }

    @Override
    public List<GoodsSaledoGongxu> listSalePro(GoodsSaledoGongxu entity) {
        return goodsSaledoGongxuMapper.listSalePro(entity);
    }

    @Override
    public List<GoodsSaledoGongxu> listSaleProByPhone(String[] idlist) {
        return goodsSaledoGongxuMapper.listSaleProByPhone(idlist);
    }
    @Override
    public List<GoodsSaledoGongxu> listSaleProFinish(GoodsSaledoGongxu entity) {
        return goodsSaledoGongxuMapper.listSaleProFinish(entity);
    }

    @Override
    public List<GoodsSaledoGongxu> selectBySaleId(String saleId) {
        return goodsSaledoGongxuMapper.selectBySaleId(saleId);
    }

    @Override
    public GoodsSaledoGongxu selectMinFinish(String saleId) {
        return goodsSaledoGongxuMapper.selectMinFinish(saleId);
    }

    @Override
    public GoodsSaledoGongxu selectLastFinish(String saleId) {
        return goodsSaledoGongxuMapper.selectLastFinish(saleId);
    }
    /**
     * 新增订单产品工艺工序关联
     * @param entity 订单产品工艺工序关联
     * @return 结果
     */
    @Override
    public int insert(GoodsSaledoGongxu entity) {
        if(StringUtils.isBlank(entity.getId())){
            entity.setId(IdUtils.fastSimpleUUID());
        }
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        return goodsSaledoGongxuMapper.insert(entity);
    }

    /**
     * 修改订单产品工艺工序关联
     * @param entity 订单产品工艺工序关联
     * @return 结果
     */
    @Override
    public int update(GoodsSaledoGongxu entity) {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return goodsSaledoGongxuMapper.update(entity);
    }
    @Override
    public int updateStatusByParentId(String status,String parentId) {
        return goodsSaledoGongxuMapper.updateStatusByParentId(status,parentId);
    }
    /**
     * 批量删除订单产品工艺工序关联
     * @param ids 需要删除的订单产品工艺工序关联主键
     * @return 结果
     */
    @Override
    public int deleteByIds(String[] ids) {
        return goodsSaledoGongxuMapper.deleteByIds(ids);
    }

    /**
     * 删除订单产品工艺工序关联信息
     * @param id 订单产品工艺工序关联主键
     * @return 结果
     */
    @Override
    public int deleteById(String id) {
        return goodsSaledoGongxuMapper.deleteById(id);
    }

    @Override
    public void deleteBySaleId(String saleId) {
        goodsSaledoGongxuMapper.deleteBySaleId(saleId);
    }

    @Override
    public int editAllTuzhihao(GoodsSaledoGongxu entity) {
        for(String id:entity.getIds()){
            GoodsSaledoGongxu lnGongyigongxu = goodsSaledoGongxuMapper.selectById(id);
            lnGongyigongxu.setShuoming(entity.getShuoming());
            lnGongyigongxu.setName(entity.getName());
            lnGongyigongxu.setGongxuName(entity.getGongxuName());
            lnGongyigongxu.setGongxuModel(entity.getGongxuModel());
            lnGongyigongxu.setDeptId(entity.getDeptId());
            lnGongyigongxu.setDeptName(entity.getDeptName());
            lnGongyigongxu.setWorkHour(entity.getWorkHour());
            lnGongyigongxu.setUpdateBy(SecurityUtils.getUsername());
            lnGongyigongxu.setUpdateTime(DateUtils.getNowDate());
            goodsSaledoGongxuMapper.update(lnGongyigongxu);
        }
        return entity.getIds().length;
    }
    @Override
    public void updateAllNotLast(String saleId) {
        goodsSaledoGongxuMapper.updateAllNotLast(saleId);
    }
    @Override
    public void updateLastById(String id) {
        goodsSaledoGongxuMapper.updateLastById( id);
    }
}
